﻿using System;
using System.Runtime.Serialization;
using System.Linq.Expressions;

namespace ExpressionSerialization
{
  [DataContract]
  public class XBinaryExpression:XExpression
  {

    [DataMember]
    public XExpression Left { get; set; }
    [DataMember]
    public XExpression Right { get; set; }
    
    public override void FromExpression(Expression source_)
    {
      base.FromExpression(source_);
      this.Left = XExpression.CreateFromExpression((source_ as BinaryExpression).Left);
      this.Right = XExpression.CreateFromExpression((source_ as BinaryExpression).Right);
    }

    public override Expression ToExpression(Type dataContract_, System.Collections.Generic.List<ParameterExpression> parameters_)
    {
      return Expression.MakeBinary(NodeType, Left.ToExpression(dataContract_,parameters_), Right.ToExpression(dataContract_,parameters_));
    }

  }
}
